package com.aaa.cars.controller;

import com.aaa.cars.entity.CarTypeConfigDetails;
import com.aaa.cars.service.CarTypeConfigDetailsService;
import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (CarTypeConfigDetails)表控制层
 *
 * @author makejava
 * @since 2020-11-17 20:31:54
 */
@RestController
@RequestMapping("carTypeConfigDetails")
public class CarTypeConfigDetailsController {
    /**
     * 服务对象
     */
    @Resource
    private CarTypeConfigDetailsService carTypeConfigDetailsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Result selectOne(Integer id) {
        if (null==id){
        throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                ExceptionConstant.ID_NOT_NULL.getErrorMessage());
    }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.carTypeConfigDetailsService.queryById(id));
}

    /**
     * 新增数据
     *
     * @param carTypeConfigDetails 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result insert(@RequestBody CarTypeConfigDetails carTypeConfigDetails){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.carTypeConfigDetailsService.insert(carTypeConfigDetails));
    }

    /**
     * 修改数据
     *
     * @param carTypeConfigDetails 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result update(@RequestBody CarTypeConfigDetails carTypeConfigDetails){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.carTypeConfigDetailsService.update(carTypeConfigDetails));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.carTypeConfigDetailsService.deleteById(id));
    }

    /**
     * 分页和模糊查询
     * @param pageNo
     * @param pageSize
     * @param carTypeConfigDetails
     * @return
     */
    @GetMapping("queryPageByParam")
    public Result queryPageByParam(Integer pageNo, Integer pageSize, CarTypeConfigDetails carTypeConfigDetails){
        return this.carTypeConfigDetailsService.queryAll(pageNo,pageSize,carTypeConfigDetails);
    }
}